import { StorageManager } from '@vben-core/shared/cache';

import { requestClient } from '#/api/request';

const storageManager = new StorageManager({
  prefix: '',
  storageType: 'sessionStorage',
});
const ADMIN_USER_ID = 'admin';

const updateFileTag = (fileId: string, tags: Record<string, any>) => {
  return requestClient.post(
    `/dsc-systemMS/dsc-file-tag/${storageManager.getItem('userId')}/${fileId}`,
    tags,
  );
};

const updatePublicFileTag = (fileId: string, tags: Record<string, any>) => {
  return requestClient.post(
    `/dsc-systemMS/dsc-file-tag/${ADMIN_USER_ID}/${fileId}`,
    tags,
  );
};

const getFileTag = (fileId: string) => {
  return requestClient.get(`/dsc-systemMS/dsc-file-tag/${fileId}`);
};

const deleteFileTag = (fileId: string) => {
  return requestClient.delete(`/dsc-systemMS/dsc-file-tag/${fileId}`);
};

const getAllByUser = () => {
  return requestClient.get(
    `/dsc-systemMS/dsc-file-tag/all/${storageManager.getItem('userId')}`,
  );
};
export default {
  updateFileTag,
  updatePublicFileTag,
  getFileTag,
  deleteFileTag,
  getAllByUser,
};
